//
//  LeftViewController.m
//  ThreeFolks
//
//  Created by Pibinuo on 15/11/28.
//  Copyright © 2015年 皮比诺. All rights reserved.
//

#import "LeftViewController.h"
#import "AppDelegate.h"
//#import "otherViewController.h"
#import "currentState.h"
#import "ScreenViewController.h"
#import "AVOSCloud.h"
@interface LeftViewController ()<UITableViewDelegate,UITableViewDataSource>
//点击登录的button
@property(nonatomic,strong)UIButton * logInButton;

@end

@implementation LeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView * imageView = [[UIImageView alloc]initWithFrame:self.view.frame];
    imageView.image = [UIImage imageNamed:@"mei.jpg"];
    [self.view addSubview:imageView];
    
    self.tableView = [[UITableView alloc]init];
    self.tableView.frame = self.view.bounds;
    self.tableView.delegate =self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    // Do any additional setup after loading the view.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.font = [UIFont systemFontOfSize:20.0f];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    
    if (indexPath.row == 0) {
        cell.textLabel.text = @"测试";
    } else if (indexPath.row == 1) {
        cell.textLabel.text = @"测试";
    } else if (indexPath.row == 2) {
        cell.textLabel.text = @"测试";
    } else if (indexPath.row == 3) {
        cell.textLabel.text = @"测试";
    } else if (indexPath.row == 4) {
        cell.textLabel.text = @"测试";
    } else if (indexPath.row == 5) {
        cell.textLabel.text = @"测试";
    }
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 180;
}

-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 150)];
    UIImageView * img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"user"]];
    img.frame = CGRectMake(20, 20, 90, 90);
    img.layer.cornerRadius = 50;
    img.userInteractionEnabled = YES;
    [view addSubview:img];
    
    self.logInButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.logInButton.frame = CGRectMake(20, 100, 90, 30);
//    self.logInButton.backgroundColor = [UIColor redColor];
    if ([currentState defaultState].isLoading == YES) {
        [self.logInButton setTitle:@"点击注销" forState:(UIControlStateNormal)];
    }else
    {
        [self.logInButton setTitle:@"点击登录" forState:(UIControlStateNormal)];
    }
    
    [self.logInButton setTitleColor:[UIColor redColor] forState:(UIControlStateNormal)];
//    self.logInButton.titleLabel.text = @"点击登录";  //这样不会显示
//    self.logInButton.titleLabel.textColor = [UIColor blackColor];//这样也是
    [self.logInButton addTarget:self action:@selector(logInButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [view addSubview:self.logInButton];
    
    
    view.backgroundColor = [UIColor clearColor];
    return view;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
#warning 待完善
}




-(void)logInButtonAction:(UIButton *)sender
{
    if ([currentState defaultState].isLoading == YES) {
        [AVUser logOut];
        [self.logInButton setTitle:@"点击登录" forState:(UIControlStateNormal)];
        [currentState defaultState].isLoading = NO;
       
    }else
    {
        ScreenViewController * scree  = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"screenVC"];
        [self showViewController:scree sender:nil];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end





